<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //自定义对象
    var user = {
        name:"tom",
        age:10,
        gender:"male",
        eat:function(){
            alert("吃饭了");
        }
    }
    alert(user.name);
    user.eat();
    //定义json
    var user1 = '{"name":"jack","age":10,"address":["北京","上海"]}';
   // alert(user1.name);错误
    //json字符串转化为json对象
    var obj = JSON.parse(user1);
    alert(obj.name);
    //json对象转化为json字符串
    alert(JSON.stringify(obj));

</script>
</html>